"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BigHandler = void 0;
const Big_1 = require("../core/Big");
const GameUtils_1 = __importDefault(require("../GameUtils"));
const Config_1 = require("../../Config");
const __1 = require("../evolution/\u5E7D\u7075");
const __2 = require("../evolution/\u987D\u77F3");
const __3 = require("../evolution/\u70AE\u53F0");
const __4 = require("../evolution/\u6076\u7075");
const __5 = require("../evolution/\u72D9\u70AE");
const __6 = require("../evolution/\u5730\u7075");
const __7 = require("../evolution/\u7CBE\u7075");
const __8 = require("../evolution/\u6C99\u5175");
const __9 = require("../evolution/\u6C99\u7687");
const __10 = require("../evolution/\u91CE\u732A");
const __11 = require("../evolution/\u91CE\u9A6C");
const __12 = require("../evolution/\u62F3\u5E08");
const __13 = require("../evolution/\u7075\u9635");
const __14 = require("../evolution/\u5929\u8C15");
const __15 = require("../evolution/\u5996\u672F");
const __16 = require("../evolution/\u9F13\u821E");
const BaseHandler_1 = require("./BaseHandler");
const Point_1 = require("../core/Point");
class BigHandler extends BaseHandler_1.BaseHandler {
    /** 大子出大 */
    bigBornBig(data, player) {
        let cost = Config_1.Config.COST_BORN_BIG;
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        if (big_start.arr_states.has(Big_1.BigState.FERTILE)) {
            cost--;
        }
        if (big_start.arr_states.has(Big_1.BigState.BURDEN)) {
            cost++;
        }
        this.handlerMgr.spendAction(player, cost);
        big_start.deleteState(Big_1.BigState.HIDE);
        let big_end = endPoint.big;
        if (big_end != null) {
            big_end.deleteState(Big_1.BigState.HIDE);
            this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("play_effect", { "effect": "big_die", "point_id": endPoint.id, "username": player.username }));
            return;
        }
        if ([Point_1.Terrain.SHAN, Point_1.Terrain.SHUI].includes(endPoint.terrain)) {
            this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("play_effect", { "effect": "big_die", "point_id": endPoint.id, "username": player.username }));
            return;
        }
        let big = new Big_1.Big();
        big.init(this.gameMgr, player, endPoint, big_start.mother, big_start);
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("born_big", { "big": big.toObj() }));
    }
    /** 大子移动 */
    bigMove(data, player) {
        let cost = Config_1.Config.COST_BIG_MOVE;
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        if (big_start.arr_states.has(Big_1.BigState.BURDEN)) {
            cost++;
        }
        this.handlerMgr.spendAction(player, cost);
        let big_end = endPoint.big;
        if (big_end != null) {
            big_end.deleteState(Big_1.BigState.HIDE);
            big_start.die(player, endPoint.id);
            return;
        }
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        big_start.terrainAdapt();
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("big_move", { "start": data.start, "end": data.end }));
        // 如果落点在九曲黄河中，自身受到一次伤害
        let mark = endPoint.getMarkNotMe(__13.阵法.九曲黄河, big_start.player);
        if (mark != null) {
            big_start.attacked(mark.big.player);
        }
    }
    /** 大子攻击 */
    bigAttack(data, player) {
        let cost = Config_1.Config.COST_BIG_ATTACK;
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        // 如果落点在地狱杀伐阵中，获得攻击消耗-2
        if (endPoint.hasMark(__13.阵法.地狱杀伐, big_start.player)) {
            cost -= 2;
        }
        // 沙地 焦渴+1
        if (big_start.arr_states.has(Big_1.BigState.BURDEN)) {
            cost++;
        }
        this.handlerMgr.spendAction(player, cost);
        let small = endPoint.small;
        let big_end = endPoint.big;
        if (small != null) {
            //小子被攻击
            small.die(player);
        }
        else if (big_end != null) {
            //大子被攻击
            if (big_end.attacked(player)) {
                //打过了，如果有嗜血，+1行动力
                if (big_start.arr_states.has(Big_1.BigState.BLOODTHIRSTY)) {
                    player.small.changeEnergy(1);
                }
                //如果有常胜，获得护盾
                if (big_start.arr_states.has(Big_1.BigState.HEROIC)) {
                    big_start.addState(Big_1.BigState.SHIELD);
                }
            }
            else {
                //攻击没打过，自己死亡
                big_start.die(player, endPoint.id);
                return;
            }
        }
        //没有大子，就是移动
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("big_attack", { "start": data.start, "end": data.end }));
        big_start.terrainAdapt();
        big_start.deleteState(Big_1.BigState.HIDE);
        // 如果落点在九曲黄河中，自身受到一次伤害
        let mark = endPoint.getMarkNotMe(__13.阵法.九曲黄河, big_start.player);
        if (mark != null) {
            big_start.attacked(mark.big.player);
        }
    }
    /** 转型 */
    evolve(data, player) {
        let point_id = data.id;
        let point = this.gameMgr.map_point.get(point_id);
        let big = point.big;
        big.actionOnce();
        big.evolution = data.evolution;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("evolve", { "player_username": big.player.username, "id": big.id, "evolution": big.evolution }, true, false), true);
        big.sonDie(player);
        let cost = 0;
        let evolution = null;
        switch (big.evolution) {
            case Big_1.BigEvolution.幽灵:
                cost = Config_1.Config.COST_BIG_EVOLVE_幽灵;
                evolution = new __1.幽灵(Big_1.BigEvolution.幽灵);
                break;
            case Big_1.BigEvolution.恶灵:
                cost = Config_1.Config.COST_幽灵_EVOLVE_恶灵;
                evolution = new __4.恶灵(Big_1.BigEvolution.恶灵);
                break;
            case Big_1.BigEvolution.炮台:
                cost = Config_1.Config.COST_BIG_EVOLVE_炮台;
                evolution = new __3.炮台(Big_1.BigEvolution.炮台);
                break;
            case Big_1.BigEvolution.狙炮:
                cost = Config_1.Config.COST_炮台_EVOLVE_狙炮;
                evolution = new __5.狙炮(Big_1.BigEvolution.狙炮);
                break;
            case Big_1.BigEvolution.顽石:
                cost = Config_1.Config.COST_BIG_EVOLVE_顽石;
                evolution = new __2.顽石(Big_1.BigEvolution.顽石);
                break;
            case Big_1.BigEvolution.地灵:
                cost = Config_1.Config.COST_BIG_EVOLVE_地灵;
                evolution = new __6.地灵(Big_1.BigEvolution.地灵);
                break;
            case Big_1.BigEvolution.精灵:
                cost = Config_1.Config.COST_BIG_EVOLVE_精灵;
                evolution = new __7.精灵(Big_1.BigEvolution.精灵);
                break;
            case Big_1.BigEvolution.沙兵:
                cost = Config_1.Config.COST_BIG_EVOLVE_沙兵;
                evolution = new __8.沙兵(Big_1.BigEvolution.沙兵);
                break;
            case Big_1.BigEvolution.沙皇:
                cost = Config_1.Config.COST_沙兵_EVOLVE_沙皇;
                evolution = new __9.沙皇(Big_1.BigEvolution.沙兵);
                break;
            case Big_1.BigEvolution.野猪:
                cost = Config_1.Config.COST_BIG_EVOLVE_野猪;
                evolution = new __10.野猪(Big_1.BigEvolution.野猪);
                break;
            case Big_1.BigEvolution.野马:
                cost = Config_1.Config.COST_BIG_EVOLVE_野马;
                evolution = new __11.野马(Big_1.BigEvolution.野马);
                break;
            case Big_1.BigEvolution.拳师:
                cost = Config_1.Config.COST_BIG_EVOLVE_拳师;
                evolution = new __12.拳师(Big_1.BigEvolution.拳师);
                break;
            case Big_1.BigEvolution.灵阵:
                cost = Config_1.Config.COST_BIG_EVOLVE_灵阵;
                evolution = new __13.灵阵(Big_1.BigEvolution.灵阵);
                break;
            case Big_1.BigEvolution.天谕:
                cost = Config_1.Config.COST_BIG_EVOLVE_天谕;
                evolution = new __14.天谕(Big_1.BigEvolution.天谕);
                break;
            case Big_1.BigEvolution.妖术:
                cost = Config_1.Config.COST_BIG_EVOLVE_妖术;
                evolution = new __15.妖术(Big_1.BigEvolution.妖术);
                break;
            case Big_1.BigEvolution.鼓舞:
                cost = Config_1.Config.COST_BIG_EVOLVE_鼓舞;
                evolution = new __16.鼓舞(Big_1.BigEvolution.鼓舞);
                break;
            default:
                console.error("有个转型体忘记写了");
        }
        evolution.evolve(big);
        this.handlerMgr.spendAction(player, cost);
    }
}
exports.BigHandler = BigHandler;
